f = open('triangle.txt','r')
data = []

for line in f:
	data.append([int(x) for x in line.split(" ")])

for x in reversed(range(len(data)-1)):
	for y in range(len(data[x])):
		data[x][y] = max(data[x+1][y]+data[x][y],data[x+1][y+1]+data[x][y])
		
print(data[0][0])